classdef netCDF_header
    properties
        id
        history
        date_created
        creator_name
        creator_url
        institution
        project
        processing_level
        acknowledgment
        station_name
        station_country
        station_institution
        station_institution_url
        station_institution_email
        geospatial_lat
        geospatial_lon
        geospatial_alt
        time_coverage_start
        time_coverage_end
        time_coverage_duration
    end
    
    methods
        function obj = netCDF_header(cfile,full)
            if nargin>0
                if nargin == 1
                    full = 0;
                end
                obj = read_netCDF_header(obj,cfile,full);
            end
        end
        %******************************************************************
        function [obj] = read_netCDF_header(obj,cfile,full)
            if nargin < 3
                full = 0;
            end
            
            ncid = netcdf.open(cfile,'NC_NOWRITE');
            %   get information about global attributes
            obj.id = netcdf.getAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'id');
            obj.station_name = netcdf.getAtt(ncid,...
                netcdf.getConstant('NC_GLOBAL'),'station_name');
            obj.geospatial_lat = netcdf.getAtt(ncid,...
                netcdf.getConstant('NC_GLOBAL'),'geospatial_lat');
            obj.geospatial_lon = netcdf.getAtt(ncid,...
                netcdf.getConstant('NC_GLOBAL'),'geospatial_lon');
            obj.geospatial_alt = netcdf.getAtt(ncid,...
                netcdf.getConstant('NC_GLOBAL'),'geospatial_alt');
            obj.time_coverage_start = netcdf.getAtt(ncid,...
                netcdf.getConstant('NC_GLOBAL'),'time_coverage_start');
            if obj.time_coverage_start > 0
                obj.time_coverage_start = -obj.time_coverage_start;
            end
            obj.time_coverage_end = netcdf.getAtt(ncid,...
                netcdf.getConstant('NC_GLOBAL'),'time_coverage_end');
            obj.time_coverage_duration = netcdf.getAtt(ncid,...
                netcdf.getConstant('NC_GLOBAL'),'time_coverage_resolution');
            if full
                obj.history = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'history');
                obj.date_created = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'datecreated');
                obj.creator_name = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'creator_name');
                obj.creator_url = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'creator_URL');
                obj.institution = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'institution');
                obj.project = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'project');
                obj.processing_level = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'processing_level');
                obj.acknowledgment = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'acknowledgment');
                obj.station_country = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'station_country');
                obj.station_institution = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'station_institution');
                obj.station_institution_url = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'station_institution_url');
                obj.station_institution_email = netcdf.getAtt(ncid,...
                    netcdf.getConstant('NC_GLOBAL'),'station_institution_email');
            end
        end
    end
end